package com.brillilab.starter.config;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import lombok.extern.slf4j.Slf4j;

@Aspect
@Slf4j
@Component
public class TimeLogggerAspect {

    @Around("execution(* com.brillilab.starter.controller..*.*(..))")
    public Object redisOptionLogging(ProceedingJoinPoint pjp) throws Throwable{
      			
        long start=System.currentTimeMillis();
        Object retVal=pjp.proceed();
        long end=System.currentTimeMillis();
        long times = end-start;
        if(times>500) {
        	ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        	HttpServletRequest request = sra.getRequest();
        	request.getRequestURI();
        	log.warn(">>>>>>>>>请求链接：{}， 执行时间:{} ms", request.getRequestURI(), times);
        }
        return retVal;
    }
}
